#include "Animation.h"

Animation::Animation(std::string filename, int frameWidth, int frameHeight, int frameCountX, int frameCountY)
{
	spriteSheet = NULL;
	width = frameWidth;
	height = frameHeight;
	fcX = frameCountX;
	fcY = frameCountY;
	currentFrameX = 0;
	currentFrameY = 0;

	spriteSheet = Drawable::LoadImage(filename);
}

Animation::~Animation()
{
	SDL_FreeSurface(spriteSheet);
}

void Animation::DrawAnimation(SDL_Surface* destinationSurface, int x, int y)
{
	SDL_Delay(30);

	frameOffSetX = width * currentFrameX;
	frameOffSetY = height * currentFrameY;

	
	currentFrameX++;
	if(currentFrameX >= fcX)
	{
		currentFrameX = 0;
		if(currentFrameY >= fcY)
			currentFrameY = 0;
		else
			currentFrameY++;
	}

	Drawable::DrawImage(destinationSurface, spriteSheet, x, y, frameOffSetX, frameOffSetY, width, height);
}